package com.qdlc.p2p.biz.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.qdlc.p2p.biz.service.AdditionalUserDrawLotteryService;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.dao.AdditionalUserDrawLotteryDao;
import com.qdlc.p2p.dal.dto.AdditionalUserDrawLottery;
import com.qdlc.p2p.dal.model.AdditionalUserDrawLotteryModel;

/**
 * Created by liaoxiangkai on 2015/11/12.
 */
@Service("additionalUserDrawLotteryService")
public class AdditionalUserDrawLotteryServiceImpl implements AdditionalUserDrawLotteryService {

    @Resource
    private AdditionalUserDrawLotteryDao additionalUserDrawLotteryDao;

    @Override
    public AdditionalUserDrawLottery getValidDrawLotteryByUserId(long userId) {
        return additionalUserDrawLotteryDao.getValidDrawLotteryByUserId(userId);
    }

    /**
     * 用户抽奖机会的列表数据
     *
     * @param model
     * @return
     */
    @Override
    public PageDataList<AdditionalUserDrawLotteryModel> list(AdditionalUserDrawLotteryModel model) {
        return additionalUserDrawLotteryDao.list(model);
    }

    /**
     * 将用户抽奖机会设置成无效
     *
     * @param status
     * @param userLotteryId
     * @return
     */
    @Override
    public int doInvalid(int status, long userLotteryId) {
        AdditionalUserDrawLottery additionalUserDrawLottery = additionalUserDrawLotteryDao.find(userLotteryId);
        if (null == additionalUserDrawLottery || additionalUserDrawLottery.getStatus() != 0) {
            return 0;
        }
        return additionalUserDrawLotteryDao.doInvalid(status, userLotteryId);
    }

}